package com.ruoyi.help.service.impl;

import com.ruoyi.help.domain.HelpStudent;
import com.ruoyi.help.domain.UserEvaluate;
import com.ruoyi.help.dto.EvaluateDto;
import com.ruoyi.help.mapper.HelpStudentMapper;
import com.ruoyi.help.service.IHelpStudentService;
import com.ruoyi.help.service.IUserEvaluateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 帮扶预约Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-10-08
 */
@Service
public class HelpStudentServiceImpl implements IHelpStudentService 
{
    @Autowired
    private HelpStudentMapper helpStudentMapper;
    @Autowired
    private IUserEvaluateService userEvaluateService;

    /**
     * 查询帮扶预约
     * 
     * @param id 帮扶预约主键
     * @return 帮扶预约
     */
    @Override
    public HelpStudent selectHelpStudentById(Long id)
    {
        return helpStudentMapper.selectHelpStudentById(id);
    }

    /**
     * 查询帮扶预约列表
     * 
     * @param helpStudent 帮扶预约
     * @return 帮扶预约
     */
    @Override
    public List<HelpStudent> selectHelpStudentList(HelpStudent helpStudent)
    {
        return helpStudentMapper.selectHelpStudentList(helpStudent);
    }

    /**
     * 新增帮扶预约
     * 
     * @param helpStudent 帮扶预约
     * @return 结果
     */
    @Override
    public int insertHelpStudent(HelpStudent helpStudent)
    {
        return helpStudentMapper.insertHelpStudent(helpStudent);
    }

    /**
     * 修改帮扶预约
     * 
     * @param evaluateDto 帮扶预约
     * @return 结果
     */
    @Override
    public int updateHelpStudent(EvaluateDto evaluateDto)
    {
        // 新建一个帮扶
        HelpStudent helpStudent = new HelpStudent();
        helpStudent.setId(evaluateDto.getId()); // 设置id
        helpStudent.setName(evaluateDto.getName()); // 设置学生姓名
        helpStudent.setWx(evaluateDto.getWx()); // 设置微信
        helpStudent.setTelephone(evaluateDto.getTelephone()); // 设置电话
        helpStudent.setTimeOfAppointment(evaluateDto.getTimeOfAppointment());
        helpStudent.setClasses(evaluateDto.getClasses());
        helpStudent.setType(evaluateDto.getType());
        helpStudent.setHelpTeacher(evaluateDto.getHelpTeacher());
        helpStudent.setStatus(evaluateDto.getStatus());
        helpStudent.setReason(evaluateDto.getReason());

        // 新建一个评价
        if (evaluateDto.getStatus() == 2) { // 成功解决
            UserEvaluate userEvaluate = new UserEvaluate();
            userEvaluate.setName(evaluateDto.getName());
            userEvaluate.setTimeOfAppointment(evaluateDto.getTimeOfAppointment());
            userEvaluate.setHelpTeacher(evaluateDto.getHelpTeacher());
            userEvaluate.setCreattime(new Date());
            userEvaluate.setReason(evaluateDto.getReason());
            userEvaluate.setRemarks(evaluateDto.getRemarks());
            userEvaluate.setEvaluate(evaluateDto.getEvaluate());
            userEvaluateService.insertUserEvaluate(userEvaluate);
        }
        return helpStudentMapper.updateHelpStudent(helpStudent);
    }

    /**
     * 批量删除帮扶预约
     * 
     * @param ids 需要删除的帮扶预约主键
     * @return 结果
     */
    @Override
    public int deleteHelpStudentByIds(Long[] ids)
    {
        return helpStudentMapper.deleteHelpStudentByIds(ids);
    }

    /**
     * 删除帮扶预约信息
     * 
     * @param id 帮扶预约主键
     * @return 结果
     */
    @Override
    public int deleteHelpStudentById(Long id)
    {
        return helpStudentMapper.deleteHelpStudentById(id);
    }
}
